<?php

namespace App\Console\Commands\Shop;

use App\Kuafu\Shop\Enum\CodeEnum;
use App\Kuafu\Shop\Model\Shop;
use App\Kuafu\Shop\Service\ShopService;
use Illuminate\Console\Command;

class InitShortName extends Command
{
    protected $signature = 'initShortName';

    protected $description = '初始化门店简称';


    public function handle()
    {
        Shop::query()
            ->where('status', CodeEnum::SHOP_STATUS_NORMAL)
            ->where("shortName", '=', '')
            ->where('addressPrefix', '!=', '')
            ->where('addressPrefix', '!=', '--')
            ->chunkById(100, function ($shopModel) {
                foreach ($shopModel as $info) {
                    if (mb_substr($info['name'], -2, 2) == '的店') { // 使用个人名称的店 先不修改
                        continue;
                    }
                    $shortName = ShopService::getShortName($info->toArray());// 门店简称

                    $this->info(vsprintf('%s 门店 简称 %s',
                        [$info['shopCode'] . $info['name'], $shortName]));
                }
            });
    }

}
